<?php

namespace App\Models\OpenShop\SiteLocation;

use App\Models\BaseModel;
use App\Models\Common\MapNationalCommunityModel;
use App\Models\Common\MapNationalStreetModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class OpenShopSiteLocationWangguiRelationModel extends BaseModel
{
    use HasFactory;

    protected $table = 'open_shop_site_location_wanggui_relation';

    protected $fillable = [
        'siteId',
        'wgNumber',
        'grade',
        'match',
        'type',
        'status',
        'createdAt',
        'createdByUid',
        'updatedAt',
        'updatedByUid',
    ];

    /*
     * 是否匹配
     */
    const MATCH_OFF = 0;
    const MATCH_ON  = 1;

    const MATCH_MAPPING = [
        self::MATCH_OFF => '未匹配',
        self::MATCH_ON  => '已匹配',
    ];

    /**
     * 网规类型
     */
    const TYPE_STREET    = 1; // 街道
    const TYPE_COMMUNITY = 2; // 社区


    public static function getWgName($wangguiRelationModel)
    {
        if ($wangguiRelationModel == null) {
            return '-';
        }
        switch ($wangguiRelationModel->type) {
            case self::TYPE_STREET:
                return MapNationalStreetModel::query()->where('wgNumber', $wangguiRelationModel->wgNumber)->value('name');
            case self::TYPE_COMMUNITY:
                return MapNationalCommunityModel::query()->where('wgNumber', $wangguiRelationModel->wgNumber)->value('name');
            default:
        }
        return '-';
    }
}
